#ifndef _STACK_H
#define _STACK_H

/** @file
 * Defines global structures and functions implemented and used by stack.c
 */

/** Stack node. */
struct stack_n {
	/** Pointer to the next node in the stack. */
	struct stack_n *next;
	/** Pointer to a value for the node. */
	void *value;
};

/** Stack base. */
typedef struct stack {
	/** Pointer to the next item on the stack. */ 
	struct stack_n *sp;
} stackt;

/**
 * Allocates data onto the heap ready for reference by a stack node.
 * @param size Size of the data being copied.
 * @param data Data to copy/alloc.
 * @return Pointer to data on success (must be destroyed), NULL on fail.
 */
void *salloc(int size, void *data);

/**
 * Pushes a new value onto the stack.
 * @param stk Stack object to push data to.
 * @param value Value to allocate, see salloc().
 */
void push(stackt *stk, void *value);

/**
 * Pops a value from the stack. Must be freed if salloc() used.
 * @param Stack to pop the next value from. 
 * @return Value on success, NULL on fail or empty stack.
 */
void *pop(stackt *stk);
#endif
